package controllers.user;

import models.ApplicationUser;
import play.db.jpa.JPABase;
import play.mvc.Controller;

/**
 * @author Elena Kudryashova
 */
public class UserController extends Controller {

    public static void index() {
        String uid = session.get("uid");
        ApplicationUser user = ApplicationUser.findById(Long.parseLong(uid));
        renderArgs.put("user", user);
        render();
    }
    public static void getInfo(){
        String uid = session.get("uid");
        ApplicationUser user = ApplicationUser.findById(Long.parseLong(uid));
        renderArgs.put("user", user);
        render();
    }

    public static void updateUser(ApplicationUser user) {
        String uid = session.get("uid");
        ApplicationUser oldUser = ApplicationUser.findById(Long.parseLong(uid));
        oldUser.email = user.email;
        oldUser.name = user.name;
        oldUser.country = user.country;
        oldUser.dateOfBirthday = user.dateOfBirthday;
        oldUser.language = user.language;
        oldUser.save();
        index();
    }
}
